package com.jolink.omiis.wechat.api;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.jolink.omiis.wechat.SpringContextUtil;
import com.jolink.omiis.wechat.faq.ExpressionConfiguration;
import com.jolink.omiis.wechat.http.IHttpHandler;
import com.jolink.omiis.wechat.inner.IOmiisMessager;
import com.jolink.omiis.wechat.message.SessionManager;
import com.jolink.omiis.wechat.mongo.IMongodbProcessor;
import com.jolink.omiis.wechat.redis.IRedisProcessor;
import com.jolink.omiis.wechat.util.WeChatConfiguration;

/**
 * 
 * 获取服务类
 * 
 * @author WangYanqing
 *
 */
@Component
public class WeChatServiceApiUtil {

	@Autowired
	private SpringContextUtil springContextUtil;

	public WeChatServiceApiUtil() {
	}

	public IMaterialApi getMaterialApi() {
		return getService(IMaterialApi.class);
	}

	public IMongodbProcessor getMongodbProcessor() {
		return getService(IMongodbProcessor.class);
	}

	public IOmiisMessager getOmiisMessager() {
		return getService(IOmiisMessager.class);
	}

	public IRedisProcessor getRedisProcessor() {
		return getService(IRedisProcessor.class);
	}

	public IHttpHandler<?> getHttpHandler() {
		return getService(IHttpHandler.class);
	}

	public ICustomerService getCustomerService() {
		return getService(ICustomerService.class);
	}

	public SessionManager getSessionManager() {
		return SessionManager.getSessionManager();
	}

	public WeChatConfiguration getConfiguration() {
		return WeChatConfiguration.getIngleton();
	}

	public ExpressionConfiguration getExpression() {
		return getService(ExpressionConfiguration.class);
	}

	/**
	 * 获取服务扩展
	 * 
	 * @param clazz
	 * @return
	 */
	@SuppressWarnings({ "rawtypes", "static-access" })
	public <T> T getService(Class clazz) {
		return springContextUtil.getBean(clazz);
	}
}
